const apiURL = "https://discard.top:4433/be"

const wxRequest = (params, url) => {
  wx.request({
    url,
    method: params.method || 'GET',
    data: params.data || {},
    timeout:5000,
    header: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    success(res) {
      if (params.success) {
        params.success(res);
      }
    },
    fail(res) {
      if (params.fail) {
        params.fail(res);
      }
    },
    complete(res) {
      if (params.complete) {
        params.complete(res);
      }
    },
  });
};

const getActivityList = (params) => {
  wxRequest(params, `${apiURL}/activity/getAll`);
};

const getActivityInfo = (params) => {
  wxRequest(params, `${apiURL}/activity/info/` + params.query.id);
};

const getAllPartner = (params) => {
  wxRequest(params, `${apiURL}/partner/list/` + params.query.userId);
}

const addPartner = (params) => {
  params.method = "post"
  wxRequest(params, `${apiURL}/partner/add`);
}

module.exports = {
  getActivityList,
  getActivityInfo,
  getAllPartner,
  addPartner,
};
